Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance GenMultiDecay constructor #71

Merged
merged 32 commits into from
Apr 6, 2022

Conversation

simonthor
Copy link
Contributor

See #68

@codecov-commenter
Copy link

codecov-commenter commented Dec 22, 2021

Codecov Report

Merging #71 (a32d54a) into master (6efbec2) will increase coverage by 0.15%.
The diff coverage is 90.90%.

@@            Coverage Diff             @@
##           master      #71      +/-   ##
==========================================
+ Coverage   92.60%   92.75%   +0.15%     
==========================================
  Files           8        8              
  Lines         473      483      +10     
  Branches       86       91       +5     
==========================================
+ Hits          438      448      +10     
  Misses         23       23              
  Partials       12       12              
Impacted Files Coverage Δ
phasespace/fromdecay/genmultidecay.py 97.80% <81.81%> (+0.27%) ⬆️
phasespace/fromdecay/mass_functions.py 100.00% <100.00%> (ø)
phasespace/phasespace.py 89.65% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6efbec2...a32d54a. Read the comment docs.

@eduardo-rodrigues
Copy link
Contributor

Hello @simonthor. I hope you're doing well.

Shall we try and give this a push?

@jonas-eschle
Copy link
Contributor

jonas-eschle commented Jan 17, 2022

That would be a good change indeed, I won't be able to assist unfortunately as I am on vacation the next twoish weeks, after that I can support fully

@simonthor
Copy link
Contributor Author

Yes, I will likely have time to work on this now. Have I understood it correctly that the goal is to add another parameter to the GenMultiDecay.from_dict called e.g. particle_model_map that will be a dict of the form {"D0":"gauss", ...}?

@eduardo-rodrigues
Copy link
Contributor

eduardo-rodrigues commented Jan 19, 2022

More or less. See the original discussion at #63 (comment).

The part to enhance is https://github.com/zfit/phasespace/blob/master/phasespace/fromdecay/genmultidecay.py#L62-L86. Your example is

            >>> parser = DecFileParser('example_decays.dec')
            >>> parser.parse()
            >>> dst_chain = parser.build_decay_chains("D*+")
            >>> dst_chain
            {'D*+': [{'bf': 0.984,
                'fs': [{'D0': [{'bf': 1.0,
                        'fs': ['K-', 'pi+']}]},
                    'pi+']},
                {'bf': 0.016,
                 'fs': ['D+', 'gamma']}]}
            If the D0 particle should have a mass distribution of a gaussian when it decays into K- and pi+
            a `zfit` parameter can be added to its decay dict:
            >>> dst_chain["D*+"][0]["fs"][0]["D0"][0]["zfit"] = "gauss"
            >>> dst_chain
            {'D*+': [{'bf': 0.984,
                'fs': [{'D0': [{'bf': 1.0,
                        'fs': ['K-', 'pi+'],
                        'zfit': 'gauss'}]},
                    'pi+']},
                {'bf': 0.016,
                'fs': ['D+', 'gamma']}]}
           >>> dst_gen = GenMultiDecay.from_dict(dst_chain)

but, clearly, we do not want users to have to do things such as dst_chain["D*+"][0]["fs"][0]["D0"][0]["zfit"] = "gauss".
The problem can be solved with an API of the kind

from decaylanguage import DecayMode, DecayChain
dm = DecayMode(1, 'K- pi+', model='PHSP', zfit="gauss")
dc = DecayChain('D0', {'D0':dm})
dst_chain = dc.to_dict()
dst_gen = GenMultiDecay.from_dict(dst_chain)

specifying that you want to model the D0 decay with a Gauss function.

In addition, you can also allow for extra flexibility in the GenMultiDecay.from_dict constructor with a new argument to pass for example {"D0":"gauss", ...} as you mention.

To me it makes sense to have these 2 ways. That's powerful.

@simonthor
Copy link
Contributor Author

I definitely agree that the current way of adding mass functions is clunky! I have added a particle_model_map argument now but some tests seem to fail, so I will try to fix that.

The problem can be solved with an API of the kind

from decaylanguage import DecayMode, DecayChain
dm = DecayMode(1, 'K- pi+', model='PHSP', zfit="gauss")
dc = DecayChain('D0', {'D0':dm})
dst_chain = dc.to_dict()
dst_gen = GenMultiDecay.from_dict(dst_chain)

specifying that you want to model the D0 decay with a Gauss function.

I think this API should already work. since dc.to_dict() outputs a regular DecayLanguage dict.
Maybe this example should be added as an example in the documentation? I did not add it before, since I thought the main point of GenMultiDecay is to handle when there are multiple possible decays, while a DecayChain only supports one way for a particle to decay.

@simonthor
Copy link
Contributor Author

simonthor commented Feb 1, 2022

The feature has now been added and works as intended, according to tests. I will try to increase the code coverage and add some more documentation and then I think it is ready to be merged! Unless you think there is anything missing?

@eduardo-rodrigues
Copy link
Contributor

Allow me a couple more days to get back to you.

@simonthor
Copy link
Contributor Author

Of course! Sorry for the slow progress on my side as well. Other projects with deadlines pop up, which I then have to prioritize.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@eduardo-rodrigues
Copy link
Contributor

Hello @simonthor! Been a while ... the CI failures seem very easy to sort out. Can you try and push this to the end?

@simonthor
Copy link
Contributor Author

Hello! Sorry, I missed that the tests were failing but I should have fixed it now.
Pre-commit CI seems to fail on a file that I have not touched and the Codacy errors seem to be the same issue I had with the last pull request, so I feel ready to remove the WIP status!

@eduardo-rodrigues
Copy link
Contributor

Go ahead and remove the WIP tag ...

@simonthor simonthor changed the title WIP: enhance GenMultiDecay constructor Enhance GenMultiDecay constructor Mar 22, 2022
@simonthor
Copy link
Contributor Author

Morning @simonthor, can you rebase given my Flake8 fixes in #74? That should clean-up the pre-commit failures you are seeing above. Then I hope we can approve and merge.

I tried rebasing now and the pre-commit errors seem to be gone. Thank you for the fix!

@eduardo-rodrigues
Copy link
Contributor

Cool. As for the Codacy "errors" I see on the linked page above, https://app.codacy.com/gh/zfit/phasespace/pullRequest?prid=8615307, that it's trivial to get those gone. Nicer if you do that.

@jonas-eschle, going to make a release as soon as this is in :-)?

@eduardo-rodrigues
Copy link
Contributor

Ah, you're getting the same errors as on master and I see @jonas-eschle already created an issue on that, see DanielBok/nlopt-python#12.

@simonthor
Copy link
Contributor Author

simonthor commented Mar 30, 2022

Ah, you're getting the same errors as on master and I see @jonas-eschle already created an issue on that, see DanielBok/nlopt-python#12.

I see, got a bit confused when the rebase somehow caused all tests to fail.

Cool. As for the Codacy "errors" I see on the linked page above, https://app.codacy.com/gh/zfit/phasespace/pullRequest?prid=8615307, that it's trivial to get those gone. Nicer if you do that.

This is an "error" I encountered last pull request as well. The docformatter pre-commit hook moves the summary to the first line, while Codacy prefers the summary to be on the second line. So I think either Codacy or docformatter will have to be reconfigured.

@eduardo-rodrigues
Copy link
Contributor

Ah, for Scikit-HEP we use Black as formatter, and we have not been using Codacy.

@eduardo-rodrigues
Copy link
Contributor

I guess those errors can be ignored since unrelated to this MR. That would be my pragmatic approach here.

@jonas-eschle
Copy link
Contributor

jonas-eschle commented Mar 31, 2022

Yep, the errors of codacy can be removed, we actually switched already to black since a long time, I'll deactivate this

phasespace/fromdecay/mass_functions.py Outdated Show resolved Hide resolved
docs/GenMultiDecay_Tutorial.ipynb Outdated Show resolved Hide resolved
@jonas-eschle
Copy link
Contributor

zfit deps should be fixed now, as soon as it's available again we can rerun the CI and the merge it! Fine from your side @simonthor ?

@simonthor
Copy link
Contributor Author

zfit deps should be fixed now, as soon as it's available again we can rerun the CI and the merge it! Fine from your side @simonthor ?

That is fine by me! All tests seem to pass now, besides black in pre-commit which apparently has an ImportError. However, since I run pre-commit locally on all code I push here, there should not be any problems. So I think this branch is ready to be merged :)

@eduardo-rodrigues
Copy link
Contributor

Well done 👍!

@jonas-eschle
Copy link
Contributor

That is fine by me! All tests seem to pass now, besides black in pre-commit which apparently has an ImportError. However, since I run pre-commit locally on all code I push here, there should not be any problems. So I think this branch is ready to be merged :)

I agree, LGTM! Since you've been contributing a lot in the past and your coding is on a pretty good level, I've added you as a developer (still figuring out the right rights in Github), I think you should now be able to write to this repository yourself. Bear in mind, that with great power comes great responsibility and it's never wrong to ask first and oc always do changes as we have done now.
I guess you also understand the codebase good enough to be able to judge commits or PRs well.

So feel free to merge this PR yourself and welcome to the project!

@simonthor simonthor merged commit 496ae84 into zfit:master Apr 6, 2022
@simonthor
Copy link
Contributor Author

Thank you both for the help and Jonas for inviting me to zfit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants